<template>
  <div class="myCenter-container">
    <div class="main">
      <div class="mainbox boxjiushi">
        <div class="mainfbox">
          <img src="@/assets/img/icon_grzx_yyzt.png" class="mainicon">
          <span>营业状态</span>
          <van-switch class="switch" :value="checked" @input="onInput" size="24px"/>
        </div>
      </div>
      <div class="mainbox boxjiushi" @click="toshopdiscount">
        <div class="mainfbox">
          <img src="@/assets/img/icon_grzx_yhq.png" class="mainicon">
          <span>优惠券</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="touser">
        <div class="mainfbox">
          <img src="@/assets/img/icon_grzx_qhzt.png" class="mainicon">
          <span>回到客户端</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>
      <!-- 下面的是我们的切换状态的box -->
      <van-popup v-model="showchange">
        <div class="changebox">
          <img src="@/assets/img/wxusericon.png">
        </div>
      </van-popup>
      <div class="mainbox boxjiushi" @click="tousercomment">
        <div class="mainfbox">
          <img src="@/assets/img/icon_yhpl.png" class="mainicon">
          <span>用户评论</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>
      <div class="mainbox boxjiushi" @click="toshopnotice">
        <div class="mainfbox">
          <img src="@/assets/img/icon_gongao.png" class="mainicon">
          <span>公告</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="Suk_tobind">
        <div class="mainfbox">
          <img src="@/assets/img/icon_bdzfbwx.png" class="mainicon">
          <span>绑定支付宝</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="toshopdesc">
        <div class="mainfbox">
          <img src="@/assets/img/icon_bjjj.png" class="mainicon">
          <span>编辑简介</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="Suk_tomypurse">
        <div class="mainfbox">
          <img src="@/assets/img/icon_wd_wdqb.png" class="mainicon">
          <span>我的钱包</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="Suk_tojilu">
        <div class="mainfbox">
          <img src="@/assets/img/icon_wd_wddd.png" class="mainicon">
          <span>收益记录</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>

      <div class="mainbox boxjiushi" @click="Suk_eixt">
        <div class="mainfbox">
          <img src="@/assets/img/icon_grzx_tc.png" class="mainicon">
          <span>退出</span>
        </div>
        <img src="@/assets/img/icon_grzx_xl.png" class="righticon">
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      showchange: false,
      activeNames: ["1"],
      checked: true
    };
  },
  activated() {},
  created() {
    this.queryDiningOne();
//  localStorage.setItem("logintp",'shop');
  },
  methods: {
    // 下面的到收益记录
    Suk_tojilu() {
      let that = this;
      that.$router.push({
        name: "shoplist"
      });
    },
    Suk_tomypurse() {
      let that = this;
      that.$router.push({
        name: "ridewallet"
      });
    },
    // 下面切换专用户
    tochange() {
      this.showchange = true;
      // this.$router.push({
      //   name: "change"
      // });
    },
    onInput(checked) {
      if (this.checked == false) {
        this.$dialog
          .confirm({
            title: "提醒",
            message: "是否开始营业？"
          })
          .then(() => {
            let that = this;
            that.$toast.loading({
              message: "加载中..."
            });
            var Sukdata = {
              status: 1,
              id: localStorage.getItem("myshopid")
            };
            console.log(Sukdata);
            that.axios
              .post(
                that.baseUrl + "/dining/updateStatus",
                that.Qs.stringify(Sukdata),
                {
                  headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                  }
                }
              )
              .then(function(res) {
                if (res.request.status === 200) {
                  if (res.data.meta.code == 200) {
                    console.log(res.data);
                    that.checked = checked;
                    that.$toast.clear();
                  } else if (res.data.meta.code == 501) {
                  }
                }
              });
          });
      } else {
        this.$dialog
          .confirm({
            title: "提醒",
            message: "是否关闭营业？"
          })
          .then(() => {
            let that = this;
            that.$toast.loading({
              message: "加载中..."
            });
            var Sukdata = {
              status: 0,
              id: localStorage.getItem("myshopid")
            };
            console.log(Sukdata);
            that.axios
              .post(
                that.baseUrl + "/dining/updateStatus",
                that.Qs.stringify(Sukdata),
                {
                  headers: {
                    "Content-Type": "application/x-www-form-urlencoded"
                  }
                }
              )
              .then(function(res) {
                if (res.request.status === 200) {
                  if (res.data.meta.code == 200) {
                    console.log(res.data);
                    that.checked = checked;
                    that.$toast.clear();
                  } else if (res.data.meta.code == 501) {
                  }
                }
              });
          });
      }
    },
//  查询单个商家信息
    queryDiningOne() {
      let that = this;
//    that.$toast.loading({
//      message: "加载中..."
//    });
      let Sukdata = {
        id: localStorage.getItem("userid")
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/dining/queryDiningOneqianduan", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function(res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
//            console.log(res.data, 11111111111111112);
              that.status = res.data.data.status
              if (that.status == 1) {
              	that.checked = true
              } else{
              	that.checked = false
              }
//            that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    },
    // 这是我们的简介
    toshopdesc() {
      let that = this;
      that.$router.push({
        name: "shopdesc"
      });
    },
    Suk_eixt() {
      let that = this;
      that.$dialog
        .confirm({
          title: "退出",
          message: "您确定退出？"
        })
        .then(() => {
          localStorage.removeItem("userid");
          that.$router.push({
            name: "login"
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    touser() {
      let that = this;
      localStorage.removeItem("logintp")
      that.$router.push({
        name: "user"
      });
    },
    // 下面的是到我的公告去
    toshopnotice() {
      let that = this;
      that.$router.push({
        name: "shopnotice"
      });
    },
    // 下面的是到我们的评论去
    tousercomment() {
      let that = this;
      that.$router.push({
        name: "usercomment"
      });
    },
    // 下面的是到我们的优惠券去
    toshopdiscount() {
      let that = this;
      that.$router.push({
        name: "shopcount"
      });
    },
    //到支付宝绑定
    Suk_tobind() {
      let that = this;
      that.$router.push({
        name: "bind"
      });
    },
    tonotice() {
      let that = this;
      that.$router.push({
        name: "setnotice"
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.myCenter-container {
  width: 100%;
  height: 100%;
  background: #f4f4f4;
}

.boxjiushi {
  width: 90%;
  margin: 0 auto;
}

.righticon {
  width: 9px;
  height: 18px;
  vertical-align: middle;
  margin-left: 10px;
}
.switch {
  position: absolute;
  right: 0.7rem;
  top: 20%;
}

.header {
  background: #fff;
  padding: 10px 5%;
}

.userhead {
  width: 100%;
  text-align: center;
  font-size: 18px;
  padding-top: 15px;
  padding-bottom: 15px;
  background: #ffffff;
}
.userhead > img {
  display: block;
  border-radius: 50%;
  width: 22%;
  margin: 0 auto;
  margin-bottom: 5px;
}
.btn {
  width: 90%;
  margin: 0 auto;
  background: #fff;
  border-radius: 20px;
  padding-top: 10px;
  padding-bottom: 10px;
  margin-top: 15px;
  margin-bottom: 15px;
}
.btn > div {
  width: 25%;
  float: left;
  text-align: center;
  font-size: 14px;
}
.btn > div > img {
  display: block;
  width: 50%;
  margin: 0 auto;
  margin-bottom: 5px;
}
.btn:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}
.userinfo {
  display: inline-block;
  vertical-align: middle;
  margin-left: 5px;
}
span {
  color: #737373;
}
.username {
  font-size: 18px;
}

.bannerbox {
  width: 88%;
  margin: 0 auto;
}

.listicon {
  width: 50px;
  height: 50px;
  margin-bottom: 3px;
}

.banner {
  padding: 12px 0;
  overflow: hidden;
}

.bannerbox {
  display: flex;
  justify-content: space-around;
}

.sbox {
  display: inline-block;
  text-align: center;
  .listtit {
    color: #1fadff;
  }
}

.main {
  background: #fff;
  .mainfbox {
    display: inline-block;
  }
  .mainbox {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f4f4f4;
  }
  .righticon {
    margin-right: 20px;
  }
  .mainicon {
    width: 28px;
    height: 28px;
    vertical-align: middle;
  }
  span {
    display: inline-block;
    font-size: 17px;
    line-height: 17px;
    height: 100%;
    vertical-align: middle;
    line-height: 100%;
    margin-left: 15px;
  }
}
.opacitybox {
  width: 100%;
  z-index: 999;
  top: -1.49rem;
  height: 1.5rem;
}
.changebox {
  display: flex;
  img {
    width: 2rem;
    height: 2rem;
  }
}
</style>